Manual Backport of Add the -capture flag to proxy log command. into release/1.8.x #4958
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport
This is manual backport PR due to failure of
backport assistanceto cherry-pick the commit from main.Original PR: #4788 to be included in release 1.8.x
The below text is copied from the body of the original PR.
Changes proposed in this PR
Added -capture flag to proxy log command.
This will enable user to capture log for given duration and write them to a file in current working dir.
If -update-level flag is provided along with -capture flag, it will set given new log level, capture the log for given duration and reset the log level to existing one post log capture.
consul-k8s proxy log -capture 1m -update-level debug
Signal interrupt handling:
Here, with existing base command setup, if signal interrupt is received during log capture, it would exit the terminal at an instant, so log levels won't be reset back to existing levels.
So, to handle the signal interrupt while capturing log, I have modified main.go, commands.go, common/base.go which will handle signal interrupts with the help of a cleanupReqAndCompleted channel for any cli command in consul-k8s.
With the new setup of common/base.go and main.go, it will reset back the log levels back to previous one, basically main will wait unitll reset.